<?php

class spButtonsHorizontal extends spDiv
{
	public function __construct(  $data=null )
	{
		parent::__construct( $data );
		parent::setClass( "spButtonsHorizontal" );

		if ( $data!=null )
		{
			if ( isset($data["buttons"]) )
				$this->addButtons( $data["buttons"] );
		}
	}

	public function addButtons( $buttons )
	{
		$data = parent::getData();

		$form_name = isset($data["form_name"])?$data["form_name"]:"";

		foreach ( $buttons as $b )
		{
			$href = isset($b["href"])?$b["href"]:"";
			$type = isset($b["type"])?$b["type"]:"";
			$confirm = isset($b["confirm"])?$b["confirm"]:"";

			switch ( $type )
			{
				case "ajax":
					{
						$but = new spInput( $b );
						$but->addAttr( "type", "submit" );
						parent::addChild( $but );
					}
					break;

				case "link":
					{
						$but = new spAnchor( array( "class"=>"button", "content"=>$b["value"],  ) );
						parent::addChild( $but );
					}
					break;

				case "input":
					{
						$but = new spInput( array( "value"=>$b["value"] ) );
						$but->addAttr( "type", "submit" );

						if ( $href!="" && $form_name!="" )
						{
							$confirm_inject = "return true;";
							if ( $confirm!="" )
							{
								$confirm_inject = 'if (confirm("'.$confirm.'")) return true; else return false;';
							}

							//$onclick = $form_name.".action='".$href."'; {$confirm_inject}";
							$onclick = $form_name.'.action="'.$href.'"; '.$confirm_inject;

							//echo $onclick;
							$but->addAttr( "onclick", $onclick );
						}

						parent::addChild( $but );
					}
					break;
					
					
					/*
				case "input":
					{
						$but = new spInput( array( "value"=>$b["value"] ) );
						$but->addAttr( "type", "submit" );

						if ( $href!="" && $form_name!="" )
						{
							$confirm_inject = "return true;";
							if ( $confirm!="" )
							{
								$confirm_inject = "if (confirm('{$confirm}')) return true; else return false;";
							}

							$onclick = $form_name.".action='".$href."'; {$confirm_inject}";

							//echo $onclick;
							$but->addAttr( "onclick", $onclick );
						}

						parent::addChild( $but );
					}
					break;
					*/
			}
		}
	}
}

?>